// ml:run = $bin < C-small-attempt0.in > c-small.out
#include <iostream>
#include <algorithm>
#include <cstring>

int const maxn = 20;
int const inf = 1 << 30;
int f[maxn][maxn];
int a[maxn];
int n, m;

int get_min(int l, int r)
{
    int ret = inf;
    for (int i = l; i <= r; i++)
        ret = std::min(ret, a[i]);
    return ret;
}

int calc(int l, int r)
{
    if (f[l][r] > 0) return f[l][r];
    if (l == r) return f[l][r] = 0;

    int ret = 0;
    int mm = get_min(l, r);
    for (int i = l; i < r; i++)
        ret = std::max(ret, mm + calc(l, i) + calc(i + 1, r));

    return f[l][r] = ret;
}

int main()
{
    std::ios::sync_with_stdio(false);
    int T; std::cin >> T;
    for (int ti = 1; ti <= T; ti++) {
        std::cout << "Case #" << ti << ": ";
        std::cin >> n >> m;

        std::memset(f, 0, sizeof(f));

        for (int i = 1; i <= m; i++)
            std::cin >> a[i];

        std::cout << calc(1, m) << "\n";
    }
}

